<?php if ( !defined('BASEPATH')) exit('No direct script access allowed');

class Map_markers extends CI_Controller {

	public function __construct(){
		parent::__construct();
		$this->load->model('wus');
		$this->load->model($this->session->userdata('formodel'));
		$this->load->library('variable');

	}
	public function index(){
	  $this->load->view('layouts/header',$this->variable->load_data($this->session->userdata('title')));
	  $this->load->view($this->session->userdata('formain'),array(
	  		'markers'	=> $this->map_markers_model->get_markers()
	  	));
	  $this->load->view('layouts/footer');
	 }

	 public function gen_selection(){
	 		$query = $this->map_markers_model->get_markers();
	 		echo json_encode($query);
	 }

	 public function insert_marks(){

	 	$check = $this->map_markers_model->check_range($this->input->post('r_from'));
	 	$check2 = $this->map_markers_model->check_range($this->input->post('r_to'));
	 	if($check[0]->error == 1){
	 		echo json_encode($check);
	 	}else if($check2[0]->error == 1){
	 		echo json_encode($check2);
	 	}
	 	else{
	 		$data = array(
	 			':p_range_from'		=>	$this->input->post('r_from'),
	 			':p_range_to'		=>	$this->input->post('r_to'),
	 			':p_mark_code'		=>	$this->input->post('color'),
	 			':p_user_id'		=>	$this->session->userdata('user_id')
	 		);	
		 	$query= $this->map_markers_model->insert_markers($data);
		 	if($query[0]->error == 1){
				echo json_encode($query);
			}else{
				$this->view_mark_list();
			}
	 	}

	 	
	 }

	public function delete_range(){
		$data = array(
			':p_range_id'	=> $this->input->post('range_id')
		);
		$query= $this->map_markers_model->delete_range($data);
		 	if($query[0]->error == 1){
				echo json_encode($query);
			}else{
				$this->view_mark_list();
			}
	}

	public function view_mark_list(){
		$this->map_markers_model->get_all();
	}

	public function add_form(){
		$this->load->view($this->session->userdata('foradd'));
	}
	public function edit_form($id){
			$this->load->view($this->session->userdata('foredit'),array(
				));
	}
	public function view_form($id){
			$this->load->view($this->session->userdata('forview'),array(
				));
	}

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */